package com.qolome.utils.web;

import java.io.Serializable;

import com.qolome.enums.ResultEnum;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
 * 
 * @Description 问我
 * @author 姜锋
 * @date 2019年12月24日 下午7:53:08 
 * @version V1.0   
 *
 * @param <T>
 */

@Data
@Builder
@AllArgsConstructor
public class HttpResult<T> implements Serializable {
	private static final long serialVersionUID = 1786915944693543249L;
	
	@ApiModelProperty(value = "状态码")
	private Integer code;
	
	@ApiModelProperty(value = "信息")
	private String message;
	
	@ApiModelProperty(value = "异常信息")
	private String exception;
	
	@ApiModelProperty(value = "数据")
	private T data;
	
	@ApiModelProperty(value = "全局流水号")
	private String globalserialNumber;

	
	private HttpResult(ResultEnum resultEnum, String globalserialNumber) {
		this.code = resultEnum.getCode();
		this.message = resultEnum.getMessage();
		this.globalserialNumber = globalserialNumber;
	}
	private HttpResult(ResultEnum resultEnum, T data, String globalserialNumber) {
		this.code = resultEnum.getCode();
		this.message = resultEnum.getMessage();
		this.data = data;
		this.globalserialNumber = globalserialNumber;
	}
	
	public static HttpResult<Void> success(String globalserialNumber) {
		return new HttpResult<Void>(ResultEnum.SUCCESS,globalserialNumber);
	}
	public static <T>HttpResult<T> success(T data, String globalserialNumber) {
		return new HttpResult<T>(ResultEnum.SUCCESS, data,globalserialNumber);
	}
	
	public static HttpResult<Void> resultEnum(ResultEnum resultEnum,String globalserialNumber) {
		return new HttpResult<Void>(resultEnum,globalserialNumber);
	}
	
  	public static <T>HttpResult<T> exception (ResultEnum resultEnum,String exception,String globalserialNumber) {
		return new HttpResult<>(resultEnum.getCode(),resultEnum.getMessage(),exception,null,null);
	}
	
	public static <T>HttpResult<T> operate (Integer code, String message) {
		return new HttpResult<>(code,message,null,null,null);
	}

}
